package cn.lym.zxxx.config;

import java.io.IOException;
import java.net.URL;
import java.util.Properties;

public class SessionConfig {

    private static Properties getProperties() {
        String CACHE_KEY = "SHARE_SESSION_CONFIG";
        return CurrentContextCache.get(CACHE_KEY, () -> {
            try {
                Properties propsNew = new Properties();
                URL url = Thread.currentThread().getContextClassLoader().getResource("sessionparameter.properties");
                if (url == null) {
                    propsNew.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("sessionparameter_default.properties"));
                } else {
                    propsNew.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("sessionparameter.properties"));
                }
                return propsNew;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    }

    public static String getValue(String key) {
        Properties props = getProperties();
        return props.getProperty(key);
    }

    public static void updateProperties(String key, String value) {
        Properties props = getProperties();
        props.setProperty(key, value);
    }
}
